var userid;
layui.config({
	version:'1510164124181'
}).use(['form', 'laypage', 'layer', 'element'],function(){
	form = layui.form;
	layer = layui.layer;
	$ = layui.jquery;
	laypage = layui.laypage;//分页
	element = layui.element; //元素操作
	$("input[name='parent_info']").click(function(){
		if(this.checked){
			if($(this).val()==1||$(this).val()=='1'){
				$("#parent_menu").show();
			}else{
				$("#parent_menu").hide();
			}
		}
	})
	role();
});
//全选
 function role() {
	 var open="";
	 $.ajax({
		 type: "GET",
		 url: httpurl + "/callRole",
		 cache: false,
		 headers: {
			 "Access-Control-Allow-Origin": "*",
			 "Access-Control-Allow-Methods": "*",
			 "Access-Control-Allow-Headers": "Authorization",
			 "Authorization": GetTokenInfo()
		 },
		 contentType : 'application/json',
		 success: function (data) {
			 console.log(JSON.stringify(data));
			// console.log(username);
			 if (data.rtnCode == 200) {
				 var list=data.data;
			 	  for (var i=0;i<list.length;i++) {
					  open += " <option value='" + list[i].id + "'>" + list[i].roleName + "</option>";
				  }
			 	  $("#user_roleSelect").html(open);
			 }
		 }
	 })
 };
function add_userinfo() {
	var roleId = $("#user_roleSelect option:selected").val();//父级菜单id
	var user_admin=$("#user_admin").val();
	var user_password=$("#user_password").val();
	var user_zhang=$("#user_zhang").val();
	$.ajax({
		type: "POST",
		url: httpurl + "/insertUser",
		cache: false,
		headers: {
			"Access-Control-Allow-Origin": "*",
			"Access-Control-Allow-Methods": "*",
			"Access-Control-Allow-Headers": "Authorization",
			"Authorization": GetTokenInfo()
		},
		contentType : 'application/json',
		data: JSON.stringify({
			"username":user_zhang,
			"password":user_password,
			"role.id":roleId,
			"admin":user_admin
		}),
		success: function (data) {
			console.log(JSON.stringify(data));
			if (data.rtnCode == 200) {
				layer.msg(data.msg);
			}else {
				layer.msg(data.msg);
			}
		},error:function (data) {
		layer.msg("读取接口失败,请稍后再试试");
	  }
	})
};

